package cn.edu.hpu.web;


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.hpu.dao.GoalDao;
import cn.edu.hpu.entity.Employee;
import cn.edu.hpu.entity.Goal;
import cn.edu.hpu.entity.Project;
import cn.edu.hpu.utitl.TimeUtitl;
import cn.edu.hpu.utitl.UUIDUtitl;

public class NewGoalServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		String gname = request.getParameter("gname");
		String gdsp = request.getParameter("gdsp");
		String gid = UUIDUtitl.getUUID();
		String gctime = TimeUtitl.getTime();
		HttpSession session = request.getSession();
		Employee e = (Employee) session.getAttribute("employee");
		String eid = e.getEid();
		Project p = (Project)session.getAttribute("project");
		 String pid = p.getPid();//
		GoalDao gd = new GoalDao();
		Goal g = new Goal();
		g.setEid(eid);
		g.setGctime(gctime);
		g.setGdsp(gdsp);
		g.setGname(gname);
		g.setPid(pid);
		try {
			gd.insertAGoal(gid,gname,gdsp,gctime,eid,pid);
			/*List<Goal> list =(List<Goal>) session.getAttribute("glist");
			if (list == null) {
				list = new ArrayList<Goal>();
			}
			list.add(g);*/
			List<Goal> list = gd.findAllGoal();
			session.setAttribute("glist", list);
			request.getRequestDispatcher("/WEB-INF/views/goal.jsp").forward(request, response);
		} catch (Exception e2) {
			request.getRequestDispatcher("/WEB-INF/views/new_goal.jsp").forward(request, response);
		}
		
	}
}
